package com.store.practice.service.impl;

import cn.hutool.core.date.DateUtil;
import com.store.practice.mapper.BgAppointmentOrderMapper;
import com.store.practice.model.BgAppointmentOrder;
import com.store.practice.model.BgAppointmentOrderExample;
import com.store.practice.service.HomePageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class HomePageServiceImpl implements HomePageService {
    @Autowired
    private BgAppointmentOrderMapper orderMapper;

    @Override
    public Map getInfo(Integer storeId, Date date) {
        Map<String, Integer> result = new HashMap<>();
        BgAppointmentOrderExample example = new BgAppointmentOrderExample();
        BgAppointmentOrderExample.Criteria criteria = example.createCriteria();
        criteria.andStoreIdEqualTo(storeId);
        if (date!=null){
            criteria.andServiceDateBetween(DateUtil.beginOfDay(date),DateUtil.endOfDay(date));
        }else {
            date = new Date();
            criteria.andServiceDateBetween(DateUtil.beginOfDay(date), DateUtil.endOfDay(date));
        }
        List<BgAppointmentOrder> orders = orderMapper.selectByExample(example);
        ArrayList<BgAppointmentOrder> list1 = new ArrayList<>();
        ArrayList<BgAppointmentOrder> list2 = new ArrayList<>();
        for (BgAppointmentOrder order:orders){
            if (order.getStatus()==1)
                list1.add(order);
            if (order.getStatus()==2)
                list1.add(order);
                list2.add(order);
        }
        result.put("orderNum",list1.size());
        result.put("arriveNum",list2.size());
        return result;
    }
}
